using System;
using Spring.Util;

namespace Sedna.Core.Common.Objects.Navigation
{
    /// <summary>
    /// Represents parsed node in the navigation expression.
    /// </summary>
    [Serializable]
    internal class StringLiteralNode : NavigationNode
    {
        private string nodeValue;

        /// <summary>
        /// Creates instance of the node.
        /// </summary>
        /// <param name="parent">Parent node.</param>
        /// <param name="nodeExpression">This node's expression.</param>
        public StringLiteralNode(NavigationNode parent, string nodeExpression) : base(parent, nodeExpression, typeof(string))
        {
            nodeValue = StringUtils.StripFirstAndLastCharacter(nodeExpression);
        }

		protected override object GetValueRecursive(bool autoCreate)
		{
            return nodeValue;
        }

        /// <summary>
        /// Sets node's value for the given context.
        /// </summary>
        /// <param name="newValue">New value for this node.</param>
        protected override void SetValue(object newValue)
        {
            throw new NotSupportedException("Can't set the value of the string literal.");
        }
    }
}